package ru.gerunn.silent.message;

import ru.gerunn.silent.common.Writer;
import ru.gerunn.silent.exception.SilentSendMessageException;
import ru.gerunn.silent.exception.SilentWriteMessageException;
import ru.gerunn.silent.server.Session;

@SuppressWarnings("serial")
public class TextMessage implements Message {

	private String string;
	private Session ownerSession;

	public TextMessage() {
	}

	public TextMessage(String string) {
		this.string = string;
	}

	public TextMessage(Session ownerSession, String string) {
		this.ownerSession = ownerSession;
		this.string = string;
	}

	public String getString() {
		return this.string;
	}

	public void send(Writer writer) throws SilentSendMessageException {
		try {
			writer.write(this);
		} catch (SilentWriteMessageException e) {
			throw new SilentSendMessageException("SilentWriteMessageException", e.getCause());
		}
	}

	public String toString() {
		return this.string;
	}

	public Session getOwnerSession() {
		return this.ownerSession;
	}

}
